<template>
  <div class="index">
    <el-card class="top-card">
      <el-form :inline="true" :model="formInline" class="demo-form-inline">
        <el-form-item label="设备编号:">
          <el-input v-model="formInline.user" placeholder="请输入" />
        </el-form-item>
        <el-form-item>
          <el-button
            type="primary"
            class="search"
            @click="onSearch"
          ><i class="el-icon-search" />查询</el-button>
        </el-form-item>
      </el-form>
    </el-card>
    <el-card class="box-card">
      <el-table
        :data="tableData"
        style="width: 100%;"
        highlight-current-row
        type="index"
        :header-cell-style="{background:'#f3f6fb',color:'#666666','font-size':'14px','font-weight':'400','border-color': '#fff'}"
        :cell-style="{'border-color': '#fff'}"
        :row-style="{'border-color': '#fff'}"
      >
        <el-table-column label="序号" type="index" width="200" />
        <el-table-column prop="innerCode" label="设备编号" />
        <el-table-column prop="type.name" label="设备型号" />
        <el-table-column prop="node.name" label="详细地址" />
        <el-table-column prop="vmStatus" label="运营状态">
          <template #default="{row}">
            <span>{{ row.vmStatus === 0 ? '未投放' : row.vmStatus === 1 ? '运营' : '撤机' }}</span>
          </template>
        </el-table-column>
        <el-table-column prop="vmStatus" label="设备状态" width="300">
          <div class="status">
            <span class="left">离线</span>
            <span class="center">货道</span>
            <span class="right">转动轴</span>
          </div>
        </el-table-column>
        <el-table-column prop="address" label="操作" width="150">
          <template #default="{row}">
            <el-button type="text" @click="openDetail(row)">查看详情</el-button>
          </template>
        </el-table-column>
      </el-table>
      <!-- 分页展示 -->
      <div class="footer">
        <div class="left">
          <span class="text">共{{ total }}条记录</span>
          <span class="text">第{{ pageIndex }}/{{ totalPage }}页</span>
        </div>
        <div class="right">
          <el-button size="small" :disabled="pageIndex === '1'" @click="toTop">上一页</el-button>
          <el-button size="small" :disabled="pageIndex === totalPage" @click="toNext">下一页</el-button>
        </div>
      </div>
    </el-card>
    <statusVue
      ref="status"
    />
  </div>
</template>

<script>
import { getEquipmentList } from '@/api/equipment'
import statusVue from './components/status.vue'
export default {
  name: 'Equipment',
  components: {
    statusVue
  },
  data() {
    return {
      formInline: {
        user: ''
      },
      formBase: {
        innerCode: null,
        type: null,
        node: null,
        ownerName: null,
        capacity: null,
        time: null,
        area: null,
        address: null,
        id: null,
        nodeId: null,
        fault: null
      },
      tableData: [{
        date: '2016-05-02',
        name: '王小虎',
        address: '上海市普陀区金沙江路 1518 弄'
      }, {
        date: '2016-05-04',
        name: '王小虎',
        address: '上海市普陀区金沙江路 1517 弄'
      }, {
        date: '2016-05-01',
        name: '王小虎',
        address: '上海市普陀区金沙江路 1519 弄'
      }, {
        date: '2016-05-03',
        name: '王小虎',
        address: '上海市普陀区金沙江路 1516 弄'
      }],
      total: null,
      pageIndex: null,
      totalPage: null,
      queryObj: {
        pageIndex: 1,
        pageSize: 10
      },
      multipleSelection: [],
      rowInfo: {
        id: null
      }
    }
  },
  created() {
    this.initTable()
  },
  methods: {
    async initTable(obj) {
      const data = await getEquipmentList({ ...this.queryObj, ...obj })
      console.log(data)
      this.tableData = data.currentPageRecords
      this.total = data.totalCount
      this.pageIndex = data.pageIndex
      this.totalPage = data.totalPage
    },
    openAdd() {
      this.$refs.flag.dialogFormV()
    },
    openUpdata(row) {
      this.formBase = {
        innerCode: row.innerCode,
        type: row.type.name,
        node: row.node.name,
        ownerName: row.ownerName,
        capacity: row.type.vmCol,
        time: row.updateTime,
        area: row.region.name,
        address: row.node.name,
        id: row.id,
        nodeId: row.nodeId,
        fault: row.fault
      }
      console.log(this.formBase)
      this.$refs.updata.dialogFormV()
    },
    closeFrom() {
      this.$refs.flag.dialogFormH()
      this.formBase = {
        innerCode: null,
        type: null,
        node: null,
        ownerName: null,
        capacity: null,
        time: null,
        area: null,
        address: null,
        id: null,
        nodeId: null,
        fault: null
      }
    },
    toTop() {
      this.queryObj.pageIndex--
      this.initTable()
    },
    toNext() {
      this.queryObj.pageIndex++
      this.initTable()
    },
    onSearch() {
      const obj = {
        innerCode: this.formInline.user
      }
      this.initTable(obj)
    },
    openDetail(row) {
      this.$refs.status.openDialog(row)
    }
  }
}
</script>

<style scoped lang="scss">
.search {
  border: #5f84ff;
  background-color: #5f84ff;
  i {
    margin-right: 5px;
  }
}
.search:hover {
  background-color: #5373e0;
}
.el-card {
  margin: 20px 30px;
}
.top-card {
  height: 85px;
  .el-input{
    width: 300px;
  }
}
.batch{
   background-color: #fbf4f0;
   border: #fbf4f0;
   color: #655b56;
}
.batch:hover{
  background-color: #f3e7e1;
}
.footer{
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-top: 20px;
    .text{
      margin-right: 10px;
      color: #dedfea;
    }
    .el-button{
    color: black;
    border-radius: 3px;
    background-color: #d5ddf8;
    border: #d5ddf8;
}
}
.status{
  display: flex;
  span{
    width: 57px;
    height: 25px;
    display: block;
    background-color: #5f84ff;
    margin-right: 20px;
    border-radius: 20px;
    text-align: center;
    line-height: 25px;
    color: #fff;
  }
  .left{
    background-color: #ffb43a;
  }
  .center{
    background-color: #42cd98;
  }
  .right{
    background-color: #42cd98;
    width: 65px;
  }
}
</style>
